package risk.client.logic;

import java.awt.Color;

import risk.client.Risk;

/**
 * @author: Mike
 */
public abstract class Player implements java.io.Serializable{
    private boolean eliminated, endTurn = false, reinforced = false, usedFortify;
    private int id;
    private Color color;
    protected Risk risk;
    private String name;
    public int strength = 0;

    /**
     * Create a new player
     * 
     * @author: Mike
     * @param id
     * @param name
     * @param color
     * @param risk
     */
    public Player(int id, String name, Color color, Risk risk) {
        this.id = id;
        this.name = name;
        this.color = color;
        this.risk = risk;
    }
    
    /**
     * New attack
     * 
     * @author: Johan
     * @param move
     */
    public void attack(Move move) {
        risk.frame.labelStatus.setText("Status: Label is working");
        new Battle(move.getStart().getArmy(), move.getTarget().getArmy(), risk);
    }
    
    /**
     * Ended turn
     * 
     * @author: Mike
     * @return endTurn
     */
    public boolean endedTurn() {
        return endTurn;
    }
    
    /**
     * End turn
     * 
     * @author: Mike
     * @param endTurn
     */
    public void endTurn(boolean endTurn) {
        this.endTurn = endTurn;
        setReinforced(false);
        usedFortify = false;
        risk.board.setSelectedNode(null); // Unselect node
    }
    
    /**
     * Fortify
     * 
     * @author: Johan
     * @param move
     */
    public void fortify(Move move) {
        move.getStart().getArmy().decreaseUnits(move.getUnits());
        move.getTarget().getArmy().increaseUnits(move.getUnits());
        risk.board.repaint();
    }

    /**
     * Get color
     * 
     * @author: Johan
     * @return color
     */
    public Color getColor(){
        return color;
    }

    /**
     * Get id
     * 
     * @author: Johan
     * @return id
     */
    public int getId(){
        return id;
    }
    
    /**
     * Get name
     * 
     * @author: Johan
     * @return name
     */
    public String getName() {
        return name;
    }
    
    /**
     * Get Selected Node
     * 
     * @author: Mike
     * @return move
     */
    public Move getSelectedMove() {
        Move move = new Move(getSelectedNode(), getSelectedNode(), 1);
        return move;
    }
    
    /**
     * Get selected node
     * 
     * @author: Mike
     * @return
     */
    public abstract Node getSelectedNode();
    
    /**
     * Is player eliminated
     * 
     * @author: Johan
     * @return eliminated
     */
    public boolean isEliminated() {
        return eliminated;
    }
    
    /**
     * @author: Pierre
     * @return reinforced
     */
    public boolean isReinforced() {
        return reinforced;
    }

    /**
     * Reinforce node
     * 
     * @author: Johan
     * @param node
     */
    public void reinforce(Node node) {
        node.getArmy().increaseUnits(1);
    }
    
    /**
     * Set eliminated
     * 
     * @author: Johan
     * @param eliminated
     */
    public void setEliminated(boolean eliminated) {
        this.eliminated = eliminated;
    }
    
    /**
     * Set setFortify
     * 
     * @author: Mike
     * @param usedFortify
     */
    public void setFortify(boolean usedFortify) {
        this.usedFortify = usedFortify;
    }
    
    /**
     * Set ID
     * 
     * @author: Johan
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }
    
    /**
     * Set reinforced
     * 
     * @author: Johan
     * @param reinforced
     */
    public void setReinforced(boolean reinforced) {
        this.reinforced = reinforced;
    }
    
    /**
     * If used fortify
     * 
     * @author: Mike
     * @return usedFortify
     */
    public boolean usedFortify() {
        return usedFortify;
    }
}